#include <bits/stdc++.h>
using namespace std;

const int N = 105;

int n, a[N], sum, p[N], i;

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }

    sum /= n;

    
    for (i = 1; i <= n; i++) {
        a[i] -= sum;
        p[i] = p[i - 1] + a[i];
    }

    sort(p + 1, p + n + 1);

    sum = 0;
    for (i = 1; i <= n; i++) {
        sum += abs(p[n / 2 + 1] - p[i]);
    }

    cout << sum;

    return 0;
}